﻿import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName test
 * @Description TODO
 * @Author ZJX
 * @Date 2024/10/27 17:29
 * @Version 1.0
 */
public class test {
    List<List<Integer>> ret;
    List<Integer> path; 
    public List<List<Integer>> subsets(int[] nums) {
        ret = new ArrayList<>();
        path = new ArrayList<>();
        dfs(nums,0) ;// Depth First Search  深度优先遍历
        return ret;
    }

    private void dfs(int[] nums, int pos) {
        ret.add(new ArrayList<>(path));
        for (int i = pos; i < nums.length; i++) {
            path.add(nums[i]);
            dfs(nums,i + 1);
//            回溯
            path.remove(path.size() - 1);
        }
    }
}
